package cn.lcl.ssh.web.action;

import cn.lcl.ssh.bean.po.User;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import java.util.Map;

/**
 * 通过继承ActionSupport来代表一个Action,这个是推荐的方式
 * Created by licho on 2017/9/26 0026.
 */
public class IndexActionWithExtends extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{
    //当请求到达Action时，会被DefaultStack拦截，将查询参数自动注入进去
    private Map<String ,Object> request;//request范围内的modal值
    private Map<String,Object> session;//session范围内的值
    private Map<String,Object> application;//application范围内的值
    private User user;

    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

    /**
     * 登录业务
     * @return
     */
    public String login(){
        System.out.println(user);
        request.put("user",user);
        return "index";
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public void setApplication(Map<String, Object> map) {
        this.application=map;
    }

    @Override
    public void setRequest(Map<String, Object> map) {
        this.request=map;
    }

    @Override
    public void setSession(Map<String, Object> map) {
        this.session=map;
    }
}
